﻿@functions {
    // To support the layout classifaction below. Implementing as a razor function because we can, could otherwise be a Func<string[], string, string> in the code block following.
    string CalcuClassify(string[] zoneNames, string classNamePrefix) {
        var zoneCounter = 0;
        var zoneNumsFilled = string.Join("", zoneNames.Select(zoneName => { ++zoneCounter; return Model[zoneName] != null ? zoneCounter.ToString() : "";}).ToArray());
        return HasText(zoneNumsFilled) ? classNamePrefix + zoneNumsFilled : "";
    }
}
@{
	/* Global includes for the theme
    ***************************************************************/

	SetMeta(httpEquiv: "X-UA-Compatible", content: "IE=edge,chrome=1");
	SetMeta(name: "viewport", content: "width=device-width; initial-scale=1.0");
	
	//Style.Include("//fonts.googleapis.com/css?family=Lobster&subset=latin");
	Style.Include("site.css");
	Script.Require("jQuery");
	Script.Include("HideUrlFieldInComments.js");

	/* Some useful shortcuts or settings
	***************************************************************/

	Func<dynamic, dynamic> Zone = x => Display(x); // Zone as an alias for Display to help make it obvious when we're displaying zones

	/* Layout classification based on filled zones
	***************************************************************/

	//Add classes to the wrapper div to toggle aside widget zones on and off
	var asideClass = CalcuClassify(new[] { "AsideFirst", "AsideSecond" }, "aside-"); // for aside-1, aside-2 or aside-12 if any of the aside zones are filled
	if (HasText(asideClass))
	{
		Model.Classes.Add(asideClass);
	}

	//Add classes to the wrapper div to toggle tripel widget zones on and off
	var tripelClass = CalcuClassify(new[] { "TripelFirst", "TripelSecond", "TripelThird" }, "tripel-"); // for tripel-1, triple-2, etc. if any of the tripel zones are filled
	if (HasText(tripelClass))
	{
		Model.Classes.Add(tripelClass);
	}

	//Add classes to the wrapper div to toggle quad widget zones on and off
	var footerQuadClass = CalcuClassify(new[] { "FooterQuadFirst", "FooterQuadSecond", "FooterQuadThird", "FooterQuadFourth" }, "split-"); // for quad-1, quad-2, etc. if any of the quad zones are filled
	if (HasText(footerQuadClass))
	{
		Model.Classes.Add(footerQuadClass);
	}

	/* Inserting some ad hoc shapes
	***************************************************************/

	WorkContext.Layout.Header.Add(New.Branding(), "5"); // Site name and link to the home page
	WorkContext.Layout.Footer.Add(New.BadgeOfHonor(), "5"); // Powered by Orchard
	WorkContext.Layout.Footer.Add(New.User(), "10"); // Login and dashboard links

	/* Last bit of code to prep the layout wrapper
	***************************************************************/

	Model.Id = "layout-wrapper";
	var tag = Tag(Model, "div"); // using Tag so the layout div gets the classes, id and other attributes added to the Model
}
<div class="header">
	<div class="base">
		<div class="leftpane">
			@if (Model.Header != null) {				
					@Zone(Model.Header)				
			}
		</div>
		<div class="rightpane">
			
			<div class="content subheader">		
				@if (Model.SubHeader.Items.Count > 0 && Model.SubHeader.Items[0].ContentItem.WidgetPart.Title != null)
				{
					<h3>
						@Model.SubHeader.Items[0].ContentItem.WidgetPart.Title
					</h3>
				}
			</div>
		</div>
	</div>
</div>

<div class="menubar">
	<div class="base">
		@if (Model.Navigation != null) {
			@Zone(Model.Navigation)
		}		
	</div>
</div>
<div class="middle">
	<div class="base">
		<div class="leftpane">
		@* the model content for the page is in the Content zone @ the default position (nothing, zero, zilch) *@
			@if (Model.Content != null) {
			<div id="content" class="group">
				@Zone(Model.Content)
			</div>
			}			
		</div>
		<div class="rightpane">
			<div class="content">
				
				@if (Model.ActionBox != null) {
				
					@Zone(Model.ActionBox)									
				
				}

				@if (Model.RightPane != null)
				{
					@Zone(Model.RightPane) 
				}				
			</div>
		</div>		
	</div>
	@if(Model.Footer != null) {
        <div class="footer">
			<div class="base">
				@Zone(Model.Footer)
			</div>
		</div>
	}
</div>
<div class="down">
	<div class="base">
		
	</div>
</div>
